package com.sgl.gk.controller;

import com.sgl.common.annotation.Log;
import com.sgl.common.core.domain.AjaxResult;
import com.sgl.common.enums.BusinessType;
import com.sgl.common.utils.StringUtils;
import com.sgl.gk.domain.GkStationTypeConfiguration;
import com.sgl.gk.service.GkStationTypeConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:xec
 * @date:2022/10/31 18:50
 *
 * 工位类型配置的controller
 **/
@RestController
@RequestMapping("/gk/stationtypeconfiguration")
public class GkStationTypeConfigurationController {

    @Autowired
    GkStationTypeConfigurationService gkStationTypeConfigurationService;

    /**
     * 工位类型配置查询接口
     * @param gkStationTypeConfiguration
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult list(GkStationTypeConfiguration gkStationTypeConfiguration){
        if (gkStationTypeConfiguration.getStationTypeId() == null || gkStationTypeConfiguration.getType() == null) {
            return AjaxResult.error("工位类型和配置类型必须传");
        }
        return gkStationTypeConfigurationService.list(gkStationTypeConfiguration);
    }

    /**
     * 工位类型配置添加接口
     * @param gkStationTypeConfiguration
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    @Log(title = "工位类型配置",businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody GkStationTypeConfiguration gkStationTypeConfiguration){
        if (gkStationTypeConfiguration.getStationTypeId() == null || gkStationTypeConfiguration.getType() == null) {
            return AjaxResult.error("工位类型和配置类型必须传");
        }
        if (gkStationTypeConfiguration.getVariableIndex() == null|| StringUtils.isEmpty(gkStationTypeConfiguration.getDataType())||StringUtils
                .isEmpty(gkStationTypeConfiguration.getDisplayName())){
            return AjaxResult.error("排序号、显示名称、数据类型、变量名称必需字段验证未通过");
        }
        if (gkStationTypeConfiguration.getResultConversion()==null){
            gkStationTypeConfiguration.setResultConversion(0);
        }
        return gkStationTypeConfigurationService.add(gkStationTypeConfiguration);
    }

    /**
     * 工位类型配置修改接口
     * @param gkStationTypeConfiguration
     * @return
     */
    @PutMapping("/edit")
    @ResponseBody
    @Log(title = "工位类型配置",businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody GkStationTypeConfiguration gkStationTypeConfiguration){
        if (gkStationTypeConfiguration.getStationTypeId() == null || gkStationTypeConfiguration.getType() == null) {
            return AjaxResult.error("工位类型和配置类型必须传");
        }
        return gkStationTypeConfigurationService.edit(gkStationTypeConfiguration);
    }

    /**
     * 工位类型配置保存按钮接口
     * @param gkStationTypeConfigurationList
     * @return
     */
    @PostMapping("/editList")
    @ResponseBody
    @Log(title = "工位类型配置",businessType = BusinessType.UPDATE)
    public AjaxResult editList(@RequestBody GkStationTypeConfiguration[] gkStationTypeConfigurationList){
        return gkStationTypeConfigurationService.editList(gkStationTypeConfigurationList);
    }

    /**
     * 工位类型配置删除接口
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ResponseBody
    @Log(title = "工位类型配置",businessType = BusinessType.DELETE)
    public AjaxResult removeByIds(@PathVariable("ids") Long[] ids){
        return gkStationTypeConfigurationService.removeByIds(ids);
    }

}
